﻿using System;
using System.Linq;
using System.Data;


namespace SquidConsult.DAL
{
    public class SupervisorDS : PeopleDS
    {
        #region GetReport
        /// <summary>
        /// Get all Expense reports that have been submitted for supervisor to approve
        ///Get list of expense thabt have been rejected by accounts staff
        /// </summary>
        /// <param name="supervisorName"></param>
        /// <returns></returns>
        public IQueryable GetAllReport(string supervisorName)
        {
            var reports = from rep in context.reports
                         join con in context.consultants on rep.ConsultantId equals con.ConsultantId
                          where rep.SupervisorName == supervisorName
                          orderby rep.ReportDate
                          select new {
                                      rep.ReportId,
                                      con.ConsultantName,
                                      rep.ReportDate, 
                                      rep.TotalExpense, 
                                      rep.Status_Supervisor
                                     };
            return reports;
        }

        public IQueryable GetRejectedReport(string supervisorName)
        {
            var reports = from rep in context.reports
                          join con in context.consultants on rep.ConsultantId equals con.ConsultantId
                          where rep.SupervisorName == supervisorName  
                                && rep.Status_Account == "Reject"
                          orderby rep.ReportDate
                          select new
                          {
                              rep.ReportId,
                              con.ConsultantName,
                              rep.ReportDate,
                              rep.TotalExpense,
                              rep.Status_Supervisor
                          };
            return reports;
        }
        #endregion 

        #region Approve or reject report
        /// <summary>
        /// Aprrove or reject report
        /// </summary>
        /// <param name="reportId"></param>
        /// <param name="status"></param>
        public void UpdateStatus(Guid reportId, string status)
        {
            var rep = context.reports.Single(r => r.ReportId == reportId);

            rep.Status_Supervisor = status;

            context.SaveChanges();
        }
        #endregion 
    }
}